<script>
var lastPhoto = false;
function silas_showOptions(id) {
    if (lastPhoto) silas_hideOptions(lastPhoto)
    lastPhoto = id

    var div = document.getElementById('options-'+id)
    if (div) div.style.display='block';
    return false;
}
function silas_hideOptions(id) {
    var div = document.getElementById('options-'+id)
    if (div) div.style.display='none';
    
    var e = window.event;
	if (e) {
        e.cancelBubble = true;
    	if (e.stopPropagation) e.stopPropagation();
    }
    return false;
}
function silas_addPhoto(photoUrl, sourceUrl, width, height, title) {
    var html = 
        '<a href="'+photoUrl+'" class="tt-flickr">' +
        '<img src="'+sourceUrl+'" alt="'+title+'" width="'+width+'" height="'+height+'" border="0" />' +
        '</a> '
    if ( richedit ) {
        win.tinyMCE.execCommand('mceInsertContent', false, html);
    } else {
        win.edInsertContent(win.edCanvas, html);
    }
    return false;
}
</script>
<style>
form#photos, form#photos input {
    font-size:11px;
}
.imagewrap {
    width:auto;
    
    z-index:1;
    overflow:visible;
}
.photo-options {
    position:absolute;
    /*
    top:0px;
    left:0px;
    */
    width:125px;
    padding:5px;
    
    background:white;
    opacity:0.9;
    border:1px solid #ccc;
    font-size:10px;
    z-index:10;
    
    display:none;
}
.photo-options div.close {
    position:absolute;
    top:2px;
    right:2px;
}
.imagewrap .photo-options a {
    text-decoration:none
}
.imagewrap .photo-options a span.props {
    color:black;
}
.imagewrap .photo-options a:hover {
    text-decoration:underline;
    background:#FFF69F;
}
</style>
<div id="wrap">
<form method="post" id="photos">
Tags: <input type="text" name="tags" value="<?php echo $tags?>" size="30" />
<input type="radio" name="everyone" value="" <?php echo (!$everyone ? 'checked="checked"' : '')?> id="showmine" /><label for="showmine"> My Photos </label> &nbsp;
<input type="radio" name="everyone" value="1" <?php echo ($everyone ? 'checked="checked"' : '')?> id="showeveryone" /><label for="showeveryone"> Everyone </label>
&nbsp; &nbsp; 
<input type="submit" name="refresh" value="refresh" />
<input type="button" value="upload" onclick="window.open('http://flickr.com/photos/upload/')"/>
<!-- prolly should add a license field -->
</form>
<?php if (count($photos) == 0):?>
Sorry, no photos found!
<?php elseif (is_array($photos)):
$baseurl = get_option('silas_flickr_baseurl');
$linkoptions = get_option('silas_flickr_linkoptions');
$parts = parse_url(get_bloginfo('home'));
$home = 'http://'.$parts['host'];
?>
<div id="images">    
<?php foreach ($photos as $photo):
if ($baseurl && !$everyone && ($linkoptions != 'flickr')) {
    $photoURL = $home.$baseurl.'photo/'.$photo['id'].'/'.$photo['pagename'];
} else {
    $photoURL = $photo['info']['urls']['url'][0]['_value'];
}
?>

<div id='target<?php echo $photo['id']?>' class='attwrap left'>
	<div class='imagewrap'>
        <div class="photo-options" id="options-<?php echo $photo['id']?>">
        <?php foreach ($photo['sizes'] as $k => $size):?>
            <a href="<?php echo $size['source']?>" onclick="return silas_addPhoto('<?php echo $photoURL?>', this, '<?php echo $size['width']?>', '<?php echo $size['height']?>', '<?php echo addslashes(htmlentities($photo['title']));?>')"><?php echo $k?><span class="props"> (<?php echo $size['width']?>x<?php echo $size['height']?>)</span></a><br />
        <?php endforeach;?>
        <div class="close"><a href="#" onclick="return silas_hideOptions(<?php echo $photo['id']?>);">close</a></div>
        </div>
        <a href="<?php echo $photoURL?>" onclick="return silas_showOptions(<?php echo $photo['id']?>);"><img id="image<?php echo $photo['id']?>" src="<?php echo $photo['sizes']['Square']['source']?>" alt="<?php echo htmlentities($photo['title']);?>" height="<?php echo $photo['sizes']['Square']['height']?>" width="<?php echo $photo['sizes']['Square']['width']?>" border="0" /></a>
	</div>
</div>

<?php endforeach;?>
</div>
<?php endif; ?>

</div></div>